package com.whnk.web.controller.pm.project_manage;

import java.util.List;

import com.whnk.pm.domain.CompanyProcurement;
import com.whnk.pm.domain.ProjectInfo;
import com.whnk.pm.service.ICompanyProcurementService;
import com.whnk.pm.service.IProjectInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.whnk.common.annotation.Log;
import com.whnk.common.enums.BusinessType;

import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.common.base.AjaxResult;

/**
 * 公司采购 信息操作处理
 * 
 * @author whwhnk
 * @date 2020-02-04
 */
@Controller
@RequestMapping("/pm/companyProcurement")
public class CompanyProcurementController extends BaseController
{
    private String prefix = "pm/companyProcurement";
	
	@Autowired
	private ICompanyProcurementService companyProcurementService;
	@Autowired
	private IProjectInfoService iProjectInfoService;
	
	@RequiresPermissions("pm:companyProcurement:view")
	@GetMapping()
	public String companyProcurement()
	{
	    return prefix + "/companyProcurement";
	}
	
	/**
	 * 查询公司采购列表
	 */
	@RequiresPermissions("pm:companyProcurement:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(CompanyProcurement companyProcurement)
	{
		startPage();
        List<CompanyProcurement> list = companyProcurementService.selectCompanyProcurementList(companyProcurement);
		return getDataTable(list);
	}
	
	/**
	 * 新增公司采购
	 */
	@GetMapping("/add/{id}")
	public String add(@PathVariable("id") String projectId, ModelMap mmap)
	{
		ProjectInfo projectInfo = iProjectInfoService.selectProjectInfoByProjectId(projectId);
		mmap.put("projectInfo", projectInfo);
		return prefix + "/add";
	}
	
	/**
	 * 新增保存公司采购
	 */
	@RequiresPermissions("pm:companyProcurement:add")
	@Log(title = "公司采购", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(CompanyProcurement companyProcurement)
	{		
		return toAjax(companyProcurementService.insertCompanyProcurement(companyProcurement));
	}

	/**
	 * 修改公司采购
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		CompanyProcurement companyProcurement = companyProcurementService.selectCompanyProcurementById(id);
		mmap.put("companyProcurement", companyProcurement);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存公司采购
	 */
	@RequiresPermissions("pm:companyProcurement:edit")
	@Log(title = "公司采购", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(CompanyProcurement companyProcurement)
	{		
		return toAjax(companyProcurementService.updateCompanyProcurement(companyProcurement));
	}
	
	/**
	 * 删除公司采购
	 */
	@RequiresPermissions("pm:companyProcurement:remove")
	@Log(title = "公司采购", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(companyProcurementService.deleteCompanyProcurementByIds(ids));
	}
	
}
